import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';

import { h } from 'vue';

import { Tag } from 'ant-design-vue';

import { getRangePickerDefaultProps } from '#/utils';

import { $t } from '#/locales'

/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'nickname',
      label: $t('views.member.signin.record.nickname'),
      component: 'Input',
      componentProps: {
        placeholder: $t('views.member.signin.record.nicknamePlaceholder'),
        allowClear: true,
      },
    },
    {
      fieldName: 'day',
      label: $t('views.member.signin.config.day'),
      component: 'Input',
      componentProps: {
        placeholder: $t('views.member.signin.config.dayPlaceholder'),
        allowClear: true,
      },
    },
    {
      fieldName: 'createTime',
      label: $t('views.member.signin.record.createTime'),
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
  ];
}

/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions['columns'] {
  return [
    {
      field: 'id',
      title: $t('views.common.id'),
      minWidth: 100,
    },
    {
      field: 'nickname',
      title: $t('views.member.signin.record.nickname'),
      minWidth: 150,
    },
    {
      field: 'day',
      title: $t('views.member.signin.config.day'),
      minWidth: 120,
      formatter: ({ cellValue }) => $t(`views.member.signin.config.day`, [cellValue]),
    },
    {
      field: 'point',
      title: $t('views.member.signin.config.point'),
      minWidth: 120,
      slots: {
        default: ({ row }) => {
          return h(
            Tag,
            {
              class: 'mr-5px',
              color: row.point > 0 ? 'blue' : 'red',
            },
            () => (row.point > 0 ? `+${row.point}` : row.point),
          );
        },
      },
    },
    {
      field: 'createTime',
      title: $t('views.member.signin.record.createTime'),
      minWidth: 180,
      formatter: 'formatDateTime',
    },
  ];
}
